package org.web2024.aop;


import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.web2024.dao.UserdetailsImp;

import java.lang.reflect.Array;
import java.time.LocalDateTime;
import java.util.Arrays;

@Aspect
@Component
public class StudentAdvice {
    @Pointcut("execution(* org.web2024.service.StudentService.*(..))")
    public void savePointCut(){}

    @Before("savePointCut()")
    public void before(){
        System.out.println("before advice");
    }
    @Around("savePointCut()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable{
        UserdetailsImp userdetailsImp=(UserdetailsImp) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        String sno = userdetailsImp.getUser().getUser_no();
        String className=pjp.getTarget().getClass().getName();
        String methodName=pjp.getSignature().getName();
        Object[] args=pjp.getArgs();
        String params= Arrays.toString(args);//参数
        LocalDateTime time=LocalDateTime.now();
        Object obj = pjp.proceed();
        System.out.println("around after");
        return obj;
    }
    @After("savePointCut()")
    public void after(){
        System.out.println("after advice");
    }
}
